﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace Jinndev.Modding {

    public class Mod {

        public static readonly string LocalizationDirName = "Localization";

        public string name;
        public string description;
        public string author;
        public string version;  // Mod版本
        public string supportGame; // 支持的游戏版本

        //public bool builtin;
        public string path; // 所在文件夹路径

        // name -> Config
        private readonly Dictionary<string, Config> configDict = new Dictionary<string, Config>();

        public IReadOnlyDictionary<string, Config> ConfigDict {
            get { return configDict; }
        }

        public Mod(string path) {
            this.path = path;
        }

        public void AddConfig(Config config) {
            if (!configDict.ContainsKey(config.name)) {
                configDict.Add(config.name, config);
            }
        }

        public Config GetConfig(string name) {
            if (configDict.TryGetValue(name, out Config config)) {
                return config;
            }
            return null;
        }

        public void ClearConfig() {
            configDict.Clear();
        }

        public List<Config> GetConfigs(int configType) {
            List<Config> result = new List<Config>();
            foreach (Config config in configDict.Values) {
                if (config.category == configType) {
                    result.Add(config);
                }
            }
            return result;
        }

        public string GetLocalizationDir() {
            return Path.Combine(path, LocalizationDirName);
        }

        //public T Load<T>(string resPath) where T : Object {

        //    ResourceManager.Load<T>(path, resPath);
        //}

    }

}